package com.itheima.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;

/*
过滤操作
 */
public class Demo04 {

    public static void main(String[] args) {
       //创建集合
        ArrayList<String> list = new ArrayList<>(List.of("张三丰", "张无忌", "张翠山", "王二麻子", "张良", "谢广坤"));

      /* // 获取流
        Stream<String> stream = list.stream();
        // 过滤 filter
        Stream<String> stream2 = stream.filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return s.length() == 3;
            }
        });
       // stream2.forEach(s-> System.out.println(s));
        Stream<String> stream3 = stream2.filter(s -> s.startsWith("张"));
        //终结
        stream3.forEach(s-> System.out.println(s));*/
      list.stream()
              .filter(s->s.length()==3)
              .filter(s->s.startsWith("张"))
              .forEach(s-> System.out.println(s));




    }
}
